﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;

namespace DAO
{
    public class CTDatMonDAO
    {
        public static DataTable GetCTDatMon(int datmon)
        {
            string sql = string.Format("select ct.DONGIA*ct.SOLUONG AS THANHTIEN,ct.MACTDM,ct.MADM,m.TENMON,ct.DONGIA,ct.SOLUONG,ct.TINHTRANG,ct.GHICHU FROM DATMON dm,CHITIETDATMON ct,MONAN m WHERE  ct.MADM=dm.MADM  and m.MAMONAN=ct.MAMONAN and dm.MADM={0}", datmon);
            return DataProvider.ExcuteQuery(sql);
        }
        public static int Themchitiet(CTDatMonDTO ct)
        {
            string sql = string.Format("insert into CHITIETDATMON(MADM,MAMONAN,SOLUONG,DONGIA,TINHTRANG) VALUES('{0}','{1}','{2}','{3}',1)",ct.Madm,ct.Mamon,ct.Soluong,ct.Dongia);
            return DataProvider.ExcuteNonQuery(sql);
        }
        public static int CheckDatMon(int madm, int mamon)
        {
            string sql = string.Format("select * from CHITIETDATMON where MADM={0} and MAMONAN={1}", madm, mamon);
            DataTable dt = DataProvider.ExcuteQuery(sql);
            return dt.Rows.Count;

        }
        public static int Capnhatdatmon(int madm, int mamon, int sl)
        {
            string sql = string.Format("update CHITIETDATMON set SOLUONG=SOLUONG+'{0}' where MADM={1} AND MAMONAN={2}", sl, madm, mamon);
            return DataProvider.ExcuteNonQuery(sql);
 
        }
    }
}
